<template>
	<div class="app-container">
		<!--表单-->
		<el-form :inline="true" class="demo-form-inline">
			<el-form-item label="日期">
				<el-date-picker
					v-model="day"
					type="date"
					placeholder="选择要统计的日期"
					value-format="yyyy-MM-dd"
				/>
			</el-form-item>
			<el-button :disabled="btnDisabled" type="primary" @click="create"
				>生成</el-button
			>
		</el-form>

    <div class="chart-container">
			<div id="chart" class="chart" style="height:500px;width:100%" />
		</div>
	</div>
</template>

<script>
import daily from "@/api/statistics";
import echarts from "echarts";

export default {
	data() {
		return {
			day: "",
			btnDisabled: false,
      showEchart:false,
      chart: null,
			title: "",
			xData: [],
			yData: []
		};
	},
	methods: {
		create() {
      if(this.day){
        this.setChart();
        this.btnDisabled = true;
        daily.createStatistics(this.day).then(response => {
          this.btnDisabled = false;
          this.$message({
            type: "success",
            message: "生成成功"
          });
        });
      }
		},
    // 设置图标参数
		setChart() {
      this.showEchart=true;
			// 基于准备好的dom，初始化echarts实例
			this.chart = echarts.init(document.getElementById("chart"));
			// console.log(this.chart)
			// 指定图表的配置项和数据
			var option = {
				// x轴是类目轴（离散数据）,必须通过data设置类目数据
				xAxis: {
					type: "category",
					data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
				},
				// y轴是数据轴（连续数据）
				yAxis: {
					type: "value"
				},
				// 系列列表。每个系列通过 type 决定自己的图表类型
				series: [
					{
						// 系列中的数据内容数组
						data: [820, 932, 901, 934, 1290, 1330, 1320],
						// 折线图
						type: "line"
					}
				]
			};
			this.chart.setOption(option);
		}
	}
};
</script>
